const { sendRequest } = require('libraries/backend');

async function login(code) {
    const result = await sendRequest({
        path: '/mp/user/wxlogin',
        method: 'POST',
        data: {
            code
        },
        isAuth: false
    });
    return result.data;
}

async function getUserInfo() {
    const result = await sendRequest({
        path: '/mp/user/getuserinfo',
        method: 'GET'
    });
    return result.data;
}

async function updateUserInfo(userData) {
    const result = await sendRequest({
        path: '/mp/user/updateuserdata',
        method: 'POST',
        data: userData
    });
    return result.data;
}

async function updateUserPhone(encryptedData, iv) {
    const result = await sendRequest({
        path: '/mp/user/updateuserphone',
        method: 'POST',
        data: { encryptedData, iv }
    });
    return result.data;
}

module.exports = {
    login,
    updateUserInfo,
    getUserInfo,
    updateUserPhone
};
